package practice1_100;

public class Practice122 {
    public int maxProfit(int[] prices) {
        int dp_i_0=0;//第i次，手中没有股票，此时手中赚钱初始化0；
        int dp_i_1=Integer.MIN_VALUE;//第i次，手中存有股票，此时初始化为负无穷
        for (int i=0;i<prices.length;i++){
            dp_i_0=Math.max(dp_i_0,dp_i_1+prices[i]);
            dp_i_1=Math.max(dp_i_1,dp_i_0-prices[i]);
        }
        return  dp_i_0;
    }

    public static void main(String[] args) {
        Practice122 practice122=new Practice122();
        int a=practice122.maxProfit(new int[] {1,4,2,9});
        System.out.println(a);
    }
}
